#include <REGX52.H>
#include <math.h>

void Delay(int xms)		//@12.000MHz
{
	unsigned char i, j;
	while(xms--)
	{
		i = 2;
		j = 239;
		do
		{
			while (--j);
		} 	while (--i);
	}
}

char Reverse(unsigned char data1)
{
	data1 = ((data1 & 0xf0) >> 4) | ((data1 & 0x0f) << 4);
	data1 = ((data1 & 0xCC) >> 2) | ((data1 & 0x33) << 2);
	data1 = ((data1 & 0xAA) >> 1) | ((data1 & 0x55) << 1);
	return data1;
}
	
void main()
{
	unsigned char n='1',l='0',m='0';
	while(1)
	{
		if(P3_1==0)
		{
			Delay(20);
			while(P3_1==0);
			Delay(20);
			
			m=~n;
			l=Reverse(m);
			P2=l;
			n=n+1;
		}
	}
	
}
